package com.tank.jdk8.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created with IntelliJ IDEA.
 * User: SuQiEr
 * Date:2017/2/12
 * Time: 21:20
 * To change this template use File | Settings | File Templates.
 */
public class StreamTest10 {

    public static void main(String[] args) {
        //分组 统计操作

        Student student = new Student("zhangsan",15,80);
        Student student2 = new Student("zhangsan",17,90);
        Student student3 = new Student("wangwu",16,85);
        Student student4 = new Student("zhaoliu",15,80);

        List<Student> studentList = Arrays.asList(student,student2,student3,student4);

        //按姓名分组
        /**
        Map<String, List<Student>> map= studentList.stream().collect(Collectors.groupingBy(Student::getName));
        System.out.println(map);
        */

        //按姓名分组并统计
        /**
       Map<String,Long> map2 =  studentList.stream().collect(Collectors.groupingBy(Student::getName,Collectors.counting()));
        System.out.println(map2);
         */


        //按姓名分组并统计分数平均数
        /***/
       Map<String,Double> map4 =  studentList.stream().collect(Collectors.groupingBy(Student::getName,Collectors.averagingDouble(Student::getScore)));
        System.out.println(map4);





        //按成绩分区 满足条件的为ture 反之为false
//        Map<Boolean,List<Student>> map3 =  studentList.stream().collect(Collectors.partitioningBy(item -> item.getScore() > 100));
//        System.out.println(map3);

    }
}

